$(function(){
	
	$.ajaxSetup({async : false});
	
	var cate1 = $('select[name=type_id1]').data('value');
	var pid = $('select[name=type_id1]').data('pid');
	var cate2 = $('select[name=type_id2]').data('value');
	$.get("/api/other.system/my_cate",{pid:pid} ,function(result,status){
		if(status!='success')return;
		var _html='<option value="0">请选择</option>';
        $.each(result.data,function(index,obj){
        	if(obj.id==cate1){
                _html+='<option selected value="'+obj.id+'">'+obj.title+'</option>';
			}else{
                _html+='<option value="'+obj.id+'">'+obj.title+'</option>';
			}
		});
        $('select[name=type_id1]').html(_html);
        window.form.render();
        if(cate1>0){
            select_two();
        }
	});

    form.on('select(type_id1)', function(){
        select_two();
    });

	function select_two(){
		var pid = $('select[name=type_id1]').val();
		$.get("/api/other.system/my_cate",{pid:pid}, function(result,status){
            if(status!='success')return;
            var _html='<option value="0">请选择</option>';
            $.each(result.data,function(index,obj){
                if(obj.id==cate2){
                    _html+='<option selected value="'+obj.id+'">'+obj.title+'</option>';
                }else{
                    _html+='<option value="'+obj.id+'">'+obj.title+'</option>';
                }
            });
            $('select[name=type_id2]').html(_html);
            window.form.render();
		});
	}

});